﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IWMAG.Scripting.Interpreter;
using IWMAG.Scripting.AST;
using IWMAG.Scripting.AST.Declarations;

namespace IWMAG.Scripting.Helpers {
    // this is going to be CompileTable's runtime counterpart
    public class RuntimeTable {
        public SymbolTable<string, RunValue> Variables = new SymbolTable<string, RunValue>();
        public SymbolTable<string, FunctionDeclaration> Functions = new SymbolTable<string, FunctionDeclaration>();
        public SymbolTable<string, ExternDeclaration> Externs = new SymbolTable<string, ExternDeclaration>();
        public SymbolTable<Type, Func<object, object>> Passback = new SymbolTable<Type, Func<object, object>>();
        public ProgramDeclaration Program;
        public ScriptEngine Engine;

        public RuntimeTable Parent {
            set {
                Variables.Parent = value.Variables;
                Functions.Parent = value.Functions;
                Externs.Parent = value.Externs;
                Passback.Parent = value.Passback;
            }
        }

        public RuntimeTable(ProgramDeclaration prog) {
            Program = prog;
        }

        public void OpenScope() {
            Variables.OpenScope();
            Functions.OpenScope();
            Externs.OpenScope();
            Passback.OpenScope();
        }

        public void CloseScope() {
            Variables.CloseScope();
            Functions.CloseScope();
            Externs.CloseScope();
            Passback.CloseScope();
        }
    }
}
